import { Driver } from "../models/driver";

export default function drivermodule(app, opt, next) {
  app.get("list", (req, res) => {
    return res.createPagination(Driver);
  });
  app.post("add", async (req, res) => {
    const model = new Driver(req.body);
    model.status = 1;
    await model.save();
    return model;
  });
  app.post("update", async (req, res) => {
    const { id, ...rest } = req.body;
    await Driver.updateOne({ _id: id }, { $set: rest });
    return { msg: "ok" };
  });
  app.post("delete", async (req, res) => {
    const { id } = req.body;
    await Driver.deleteOne({ _id: id });
    return { msg: "ok" };
  });
  next();
}
export const autoPrefix = "/driver/";
